<?php

namespace App\Models\Game\Config\Broadcast;

use App\Models\Game\Model;
use App\Models\Game\Platform\Org;
use App\Models\Game\Common\Dictionary;
use App\Models\Traits\Game\LogsActivity;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Broadcast extends Model
{
    use LogsActivity;

    /**
     * 数据表名称
     *
     * @var string
     */
    protected $table = 't_config_broadcast';

    /**
     * 不可批量赋值的属性
     *
     * @var array
     */
    protected $guarded = [];

    /**
     * 进行类型转换的字段
     *
     * @var array
     */
    protected $casts = [
        'content_param' => 'array',
        'created' => 'timestamp',
        'updated' => 'timestamp'
    ];

    /**
     * 开启状态（关闭）
     */
    const ENABLE_OFF = 0;

    /**
     * 开启状态（开启）
     */
    const ENABLE_ON = 1;

    /**
     * 获得平台信息
     *
     * @return BelongsTo
     */
    public function org(): BelongsTo
    {
        return $this->belongsTo(Org::class, 'plat_code', 'code')->withTrashed();
    }

    /**
     * 拥有此邮件的所有字典【内容】
     *
     * @return BelongsToMany
     */
    public function contents(): BelongsToMany
    {
        return $this->belongsToMany(Dictionary::class, BroadcastDictionary::tableName(), 'broadcast_id', 'dict_id')->withTrashed();
    }
}
